package mercurius.fitness.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.WindowResizeListener;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

import mercurius.fitness.client.Fitness;
import net.pleso.framework.client.ui.windows.Slider;
import net.pleso.framework.client.ui.windows.Window;


public class HTMLFrame extends Window {

	private HTML frame = new HTML();
	
	public HTMLFrame(String caption,String url,String html) {
		super(null);
		init(caption,url,html);
		
	}
	
	private void init(String caption,final String url,String html) {
		this.setCaption(caption);
		int height = com.google.gwt.user.client.Window.getClientHeight() -75;
		
		html = "" +
			"<html>" +
			"<head>" +
			"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />" +
			"<title>amline</title>" +
			"</head>" +
			"<body>" +
			html +
			"</body>" +
			"</html>";
		
		GWT.log(html,null);
		frame.setHTML(html);
		frame.setSize("100%",height + "px"); 
		SimplePanel p = new SimplePanel();
		VerticalPanel v = new VerticalPanel();
		HTML link = new HTML("<a href='javascript:;'>Open in new window</a>");
		link.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				Fitness.open(url);
			}
		});
		
		 
		  
		v.add(link);
		v.add(frame);
		v.setWidth("100%");
		p.add(v);
		this.initWidget(p);
		
//		 Add a listener for browser resize events.
		com.google.gwt.user.client.Window.addWindowResizeListener(new WindowResizeListener() {
            public void onWindowResized(int width, int height)
            {
                height = height - 75;
                frame.setHeight(height + "px");
            }
        }); 
		
	}
	
	public HTMLFrame(Slider parentSlider,String caption,String url,String html) {
		super(parentSlider);
		init(caption,url,html);
	}

}
